layui.use(['table', 'admin', 'ax', 'func', 'form', 'tree', 'layer'], function () {
    var $ = layui.$;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var form = layui.form;
    var tree = layui.tree;
    var layer = layui.layer;


    var data = [];

    $.ajax(Feng.ctxPath + '/houseInfo/listHouseTree', {
        async: false,
        data: {
            xq_id: Feng.getUrlParam("relXqId")
        },
        success: function (res) {
            // console.log(res)
            if (res.message != "无数据") {
                res.data.spread = true;
                for (let i = 0; i < res.data.children.length; i++) {
                    res.data.children[i].spread = true;
                    for (let j = 0; j < res.data.children[i].children.length; j++) {
                        res.data.children[i].children[j].spread = true;
                        for (let k = 0; k < res.data.children[i].children[j].children.length; k++) {
                            res.data.children[i].children[j].children[k].spread = true;
                        }
                    }
                }
                data.push(res.data)
            }
        }
    })


    tree.render({
        elem: '#test12',
        data: data,
        //是否显示复选框
        showCheckbox: true,
        id: 'houseId',
        //是否允许点击节点时弹出新窗口跳转
        isJump: false,
        //获取当前点击的节点数据
        click: function (obj) {
            // var data = obj.data;
            // console.log(data)
        }
    });

    if (sessionStorage.getItem("arr")) {
        var arr = sessionStorage.getItem("arr").split(",")
        tree.setChecked('houseId', arr);
    }


    $('#cancel').click(function () {
        var checkData = tree.getChecked('houseId');

        var arr = new Array();
        if (checkData.length != 0) {
            for (let i = 0; i < checkData.length; i++) {
                for (let j = 0; j < checkData[i].children.length; j++) {
                    for (let k = 0; k < checkData[i].children[j].children.length; k++) {
                        for (let l = 0; l < checkData[i].children[j].children[k].children.length; l++) {
                            for (let m = 0; m < checkData[i].children[j].children[k].children[l].children.length; m++) {
                                arr.push(checkData[i].children[j].children[k].children[l].children[m].house_id);
                            }
                        }
                    }
                }
            }
        }
        // console.log(arr);
        sessionStorage.setItem("arr", arr);
        parent.layer.closeAll()
    });

});
